<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <common-head></common-head>
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp();
    const CommonChild = {
      template: `
        <div>
          <h3>这是子组件</h3>  
          {{a}}
          <br/>
          {{b}}
          <br/>
          {{c}}
          <br/>
          {{d}}
          <br/>
          {{e}}
        </div>
      `,
      // 接收时参数类型验证
      props: {
        // 只验证数据类型
        a: String,
        // 只验证类型 类型可以是多选
        b: [String, Number],
        // 验证类型 且 必须要传值
        c: {
          type: Number,
          required: true
        },
        // 验证类型 有默认值
        d: {
          type: String,
          default: '这是默认值'
        },
        e: {
          type: Array,
          default: () => [1,2,3,4]
        },
        f: {
          validator: value => {
            if(value === '小明'){
              return true
            }else{
              return false
            }
          }
        }
      }
    }
    const CommonHead = {
      template: `
        <div>
          <h2>父组件</h2>  
          <hr/>
          <common-child a="10" :b="[1,2,3]" f="小红"></common-child>
        </div>
      `,
      data() {
        return {
          msg: '动态数据'
        }
      },
      components: {
        CommonChild
      }
    }
    app.component('CommonHead', CommonHead);
    app.mount('#app')
  </script>
</body>
</html>